package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.DwBaiduLoanTempDao;
import com.fdb.efp.nls.service.domain.DwBaiduLoanTemp;
import com.fdb.efp.nls.service.facade.DwBaiduLoanTempService;
import com.fdb.efp.nls.service.vo.DwBaiduLoanTempVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;


/**
 * Service Impl: 百度联合贷-日初借据信息临时表服务实现
 * @author ligm
 * @date 2019-05-02 
 */
@Service("dwBaiduLoanTempService")
public class DwBaiduLoanTempServiceImpl implements DwBaiduLoanTempService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(DwBaiduLoanTempServiceImpl.class);

	@Autowired
	private DwBaiduLoanTempDao dwBaiduLoanTempDao;

   	/**
	 * 新增数据 
     * @param inDwBaiduLoanTempVo
     * @return 
	 */
	public int insertDwBaiduLoanTemp(DwBaiduLoanTempVO inDwBaiduLoanTempVo) {
		logger.debug("当前新增数据为:"+ inDwBaiduLoanTempVo.toString());
		int num = 0;
		try {
			DwBaiduLoanTemp dwBaiduLoanTemp = new DwBaiduLoanTemp();
			beanCopy(inDwBaiduLoanTempVo, dwBaiduLoanTemp);
			num = dwBaiduLoanTempDao.insertDwBaiduLoanTemp(dwBaiduLoanTemp);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

    /**
	 * 根据主键删除信息 
	 * @param inDwBaiduLoanTempVo
 	 * @return
	 */
	public int deleteByPk(DwBaiduLoanTempVO inDwBaiduLoanTempVo) {
		logger.debug("当前删除数据条件为:"+ inDwBaiduLoanTempVo);
		int num = 0;
		try {
			DwBaiduLoanTemp dwBaiduLoanTemp = new DwBaiduLoanTemp();
			beanCopy(inDwBaiduLoanTempVo, dwBaiduLoanTemp);
			num = dwBaiduLoanTempDao.deleteByPk(dwBaiduLoanTemp);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inDwBaiduLoanTempVo +"删除的数据条数为"+ num);
		return num;
	}


    /**
	 * 根据主键更新信息 
	 * @param inDwBaiduLoanTempVo
	 * @return 
	 */  
	public int updateByPk(DwBaiduLoanTempVO inDwBaiduLoanTempVo) {
		logger.debug("当前修改数据为:"+ inDwBaiduLoanTempVo.toString());
		int num = 0;
		try {
			DwBaiduLoanTemp dwBaiduLoanTemp = new DwBaiduLoanTemp();
			beanCopy(inDwBaiduLoanTempVo, dwBaiduLoanTemp);
			num = dwBaiduLoanTempDao.updateByPk(dwBaiduLoanTemp);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inDwBaiduLoanTempVo +"修改的数据条数为"+ num);
		return num;
	}
	
    /**
	 * 根据主键查询详情 
	 * @param dwBaiduLoanTemp
	 * @return 
	 */
	public DwBaiduLoanTempVO queryByPk(DwBaiduLoanTempVO inDwBaiduLoanTempVo) {
		
		logger.debug("当前查询参数信息为:"+ inDwBaiduLoanTempVo);
		try {
			DwBaiduLoanTemp queryDwBaiduLoanTemp = new DwBaiduLoanTemp();
			beanCopy(inDwBaiduLoanTempVo, queryDwBaiduLoanTemp);
			DwBaiduLoanTemp queryRslDwBaiduLoanTemp = dwBaiduLoanTempDao.queryByPk(queryDwBaiduLoanTemp);
			if (Objects.nonNull(queryRslDwBaiduLoanTemp)) {
				DwBaiduLoanTempVO outDwBaiduLoanTempVo = beanCopy(queryRslDwBaiduLoanTemp, new DwBaiduLoanTempVO());
				logger.debug("当前查询结果为:"+ outDwBaiduLoanTempVo.toString());
				return outDwBaiduLoanTempVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


    /**
	 * 一级数据权限 
	 * @param dwBaiduLoanTemp
	 * @return 
	 */	
	@SuppressWarnings("unchecked")
	public List<DwBaiduLoanTempVO> queryAllByLevelOne(DwBaiduLoanTempVO dwBaiduLoanTempVo) {
		logger.debug("查看当前用户对应的数据信息的参数信息为:");
		List<DwBaiduLoanTempVO> list = null;
		try {
			List<DwBaiduLoanTemp> dwBaiduLoanTemps = dwBaiduLoanTempDao.queryAllByLevelOneByPage(dwBaiduLoanTempVo);
			logger.debug("查看当前用户对应的数据信息的结果集数量为:"+ dwBaiduLoanTemps.size());
			pageSet(dwBaiduLoanTemps, dwBaiduLoanTempVo);
			list = (List<DwBaiduLoanTempVO>) beansCopy(dwBaiduLoanTemps, DwBaiduLoanTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


    /**
	 * 二级数据权限 
	 * @param dwBaiduLoanTemp
	 * @return 
	 */
	@SuppressWarnings("unchecked")
	public List<DwBaiduLoanTempVO> queryAllByLevelTwo(DwBaiduLoanTempVO dwBaiduLoanTempVo) {
		logger.debug("查看当前用户及所属机构对应的数据信息的参数信息为:");
		List<DwBaiduLoanTemp> dwBaiduLoanTemps = dwBaiduLoanTempDao.queryAllByLevelTwoByPage(dwBaiduLoanTempVo);
		logger.debug("查看当前用户及所属机构对应的数据信息的结果集数量为:"+dwBaiduLoanTemps.size());
		List<DwBaiduLoanTempVO> list = null;
		try {
			pageSet(dwBaiduLoanTemps, dwBaiduLoanTempVo);
			list = (List<DwBaiduLoanTempVO>) beansCopy(dwBaiduLoanTemps, DwBaiduLoanTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


    /**
	 * 三级数据权限 
	 * @param dwBaiduLoanTemp
	 * @return 
	 */
	@SuppressWarnings("unchecked")
	public List<DwBaiduLoanTempVO> queryAllByLevelThree(DwBaiduLoanTempVO dwBaiduLoanTempVo) {
		logger.debug("查看当前用户所在机构及下属机构对应的数据信息的参数信息为:");
		List<DwBaiduLoanTemp> dwBaiduLoanTemps = dwBaiduLoanTempDao.queryAllByLevelThreeByPage(dwBaiduLoanTempVo);
		logger.debug("查看当前用户所在机构及下属机构对应的数据信息的结果集数量为:"+ dwBaiduLoanTemps.size());
		List<DwBaiduLoanTempVO> list = null;
		try {
			pageSet(dwBaiduLoanTemps, dwBaiduLoanTempVo);
			list = (List<DwBaiduLoanTempVO>) beansCopy(dwBaiduLoanTemps, DwBaiduLoanTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	}

    /**
	 * 四级数据权限  
	 * @param dwBaiduLoanTemp
	 * @return 
	 */
	@SuppressWarnings("unchecked")
	public List<DwBaiduLoanTempVO> queryAllByLevelFour(DwBaiduLoanTempVO dwBaiduLoanTempVo) {
		logger.debug("【预留，便于后续自定义 】信息的参数信息为:");
		List<DwBaiduLoanTemp> dwBaiduLoanTemps = dwBaiduLoanTempDao.queryAllByLevelFourByPage(dwBaiduLoanTempVo);
		logger.debug("【预留，便于后续自定义 】信息的结果集数量为:"+ dwBaiduLoanTemps.size());
		List<DwBaiduLoanTempVO> list = null;
		try {
			pageSet(dwBaiduLoanTemps, dwBaiduLoanTempVo);
			list = (List<DwBaiduLoanTempVO>) beansCopy(dwBaiduLoanTemps, DwBaiduLoanTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	}

    /**
	 * 五级数据权限  
	 * @param dwBaiduLoanTemp
	 * @return 
	 */
	@SuppressWarnings("unchecked")
	public List<DwBaiduLoanTempVO> queryAllByLevelFive(DwBaiduLoanTempVO dwBaiduLoanTempVo) {
		logger.debug("【预留，便于后续自定义 】信息的参数信息为:");
		List<DwBaiduLoanTemp> dwBaiduLoanTemps = dwBaiduLoanTempDao.queryAllByLevelFiveByPage(dwBaiduLoanTempVo);
		logger.debug("【预留，便于后续自定义 】信息的结果集数量为:"+ dwBaiduLoanTemps.size());
		List<DwBaiduLoanTempVO> list = null;
		try {
			pageSet(dwBaiduLoanTemps, dwBaiduLoanTempVo);
			list = (List<DwBaiduLoanTempVO>) beansCopy(dwBaiduLoanTemps, DwBaiduLoanTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	}

	 /**
   	 * 
   	 * 分页查询【日初借据信息临时表】 <br>
   	 * 0.1:weijj:2019年5月7日 下午2:37:18:新增 <br>
   	 * 
   	 * @author weijj
   	 * @since 2019年5月7日 下午2:37:18
   	 * @date 2019年5月7日 下午2:37:18
   	 * @version 0.1
   	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<DwBaiduLoanTempVO> queryByPage(DwBaiduLoanTempVO dwBaiduLoanTempVO) {
		// TODO Auto-generated method stub
		String msg1 = "日初借据信息临时表";
		logger.debug(msg1, "message {}");
		List<DwBaiduLoanTempVO> list = null;
		try {
			List<DwBaiduLoanTemp> dwBaiduLoans = dwBaiduLoanTempDao.queryByPage(dwBaiduLoanTempVO);
			list = (List<DwBaiduLoanTempVO>) beansCopy(dwBaiduLoans, DwBaiduLoanTempVO.class);

		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);

		}
		if(list != null) {
			String msg2 = "查询的数据为大小为 " + list.size();
			logger.debug(msg2, "message {}");
		}
		return list;
	}

	/**
   	 * 
   	 * 统计【日初借据信息临时表】数据量 <br>
   	 * 0.1:weijj:2019年5月7日 下午2:37:18:新增 <br>
   	 * 
   	 * @author weijj
   	 * @since 2019年5月7日 下午2:37:18
   	 * @date 2019年5月7日 下午2:37:18
   	 * @version 0.1
   	 */
	@Override
	public int queryCount() {
		// TODO Auto-generated method stub
		String msg1 = "查询【日初借据信息临时表】表中数据量大小";
		logger.debug(msg1, "message {}");
		int num = 0;
		try {
			num = dwBaiduLoanTempDao.queryCount();
		} catch (Exception e) {
			String msg2 = "查询【日初借据信息临时表】表中数据量大小出错" + e;
			logger.debug(msg2, "message {}");
			num = -1;
		}
		return num;
	}
}
